package com.mouse.remind;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

	public static boolean isEmpty(String value) {
		return value == null || value.equals("");
	}

	public static int toInt(String string) {
		int num = 0;
		try {
			num = Integer.parseInt(string);
		} catch (Exception e) {
		}
		
		return num;
	}

	public static boolean toBoolean(String string) {
		boolean bool = false;
		try {
			bool = Boolean.parseBoolean(string);
		} catch (Exception e) {
		}
		return bool;
	}

	public static long toLong(String string) {
		long num = 0;
		try {
			num = Long.parseLong(string);
		} catch (Exception e) {
		}
		return num;
	}

	public static boolean isMobileNO(String mobiles){
		//Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
		//第一种验证方法现在不适用了，像移动的183、182就验证失败
		Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}
	
	public static String replaceHTML(String str){
		if (str != null && !str.equals("")) {
			str = str.replaceAll("&nbsp;", " ").replaceAll("<br>|<br/>|<br />", "")//\n
					.replaceAll("&quot;", "\"");
		}
		return str;
	}

}
